<template>
  <a-card
    style="margin-top: 24px"
    :bordered="false"
    title="教学任务审核结果">

    <div slot="extra" class="table-page-search-wrapper">
      <a-input-search placeholder="请输入" style="margin-left: 16px; width: 272px;" />
      <a-button type="primary" class="btnTitle">下载</a-button>
    </div>
    <!-- <s-table
      ref="table"
      size="default"
      rowKey="key"
      :columns="columns"
      data="data"
      :alert="true"
      :rowSelection="rowSelection"
      showPagination="auto"
    > -->
    <a-list size="large" :pagination="{showSizeChanger: true, showQuickJumper: true, pageSize: 5, total: 50}">
      <a-list-item :key="index" v-for="(item, index) in data">
        <div class="taskDetail">
          <p slot="owner" class="userName">{{ item.owner }}</p>
          <p slot="wordInfo" class="wordInfo">{{ item.wordInfo }}</p>
        </div>
        <div class="list-content">
          <div class="list-content-item">
            <span>上传时间</span>
            <p slot="startAt">{{ item.startAt }}</p>
          </div>
          <div class="list-content-item" slot="similarity">
            <span>相似度</span>
            <a-progress :percent="item.progress.value" :status="!item.progress.status ? null : item.progress.status" style="width: 180px" />
          </div>
        </div>
      </a-list-item>
    </a-list>
    <!-- </s-table> -->
    <create-form
      ref="createModal"
      :visible="visible"
      :loading="confirmLoading"
      :model="mdl"
      @cancel="handleCancel"
      @ok="handleOk"
    />
    <step-by-step-modal ref="modal" @ok="handleOk"/>
  </a-card>
</template>

<script>
// 演示如何使用 this.$dialog 封装 modal 组件
import TaskForm from './modules/TaskForm'
import Info from './components/Info'
import moment from 'moment'
import { STable, Ellipsis } from '@/components'
import { getRoleList, getServiceList } from '@/api/manage'

import StepByStepModal from './modules/StepByStepModal'
import CreateForm from './modules/CreateForm'
const data = []
data.push({
  owner: '袁甜甜',
  startAt: '2018-07-26 22:44',
  wordInfo: '我家有6口人：爷爷、奶奶、爸爸、妈妈、弟弟和我。',
  progress: {
    value: 90
  }
})
data.push({
  owner: '乌力杰',
  startAt: '2018-07-26 22:44',
  wordInfo: '你现在有空吗？我想问你一个问题。',
  progress: {
    value: 54
  }
})
data.push({
  owner: '朱宇',
  startAt: '2018-07-26 22:44',
  wordInfo: '明天的会议很重要，请你安排好时间，准时到场。',
  progress: {
    value: 66
  }
})
data.push({
  owner: '王建源',
  startAt: '2018-07-26 22:44',
  wordInfo: '目前看来不算严重，但是尽快治疗，不能拖延，平时饮食清淡，多休息，不要抽烟喝酒。',
  progress: {
    value: 30
  }
})
data.push({
  owner: '吴慎宇',
  startAt: '2018-07-26 22:44',
  wordInfo: '我有许多朋友，其中既有健听人，也有聋人。',
  progress: {
    // status: 'exception',
    value: 100
  }
})
const columns = [
  {
    title: '用户名',
    scopedSlots: { customRender: 'owner' }
  },
  {
    title: '一个词或一个句子',
    scopedSlots: { customRender: 'wordInfo' }
  },
  {
    title: '上传时间',
    scopedSlots: { customRender: 'startAt' }
  },
  {
    title: '相似度',
    scopedSlots: { customRender: 'similarity' }
  }
]
export default {
  name: 'StandardList',
  components: {
    TaskForm,
    Info,
    STable,
    Ellipsis,
    CreateForm,
    StepByStepModal
  },
  data () {
    this.columns = columns
    return {
      data,
      visible: false,
      confirmLoading: false,
      mdl: null,
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {},
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        console.log('loadData request parameters:', requestParameters)
        return getServiceList(requestParameters)
          .then(res => {
            return res.result
          })
      },
      selectedRowKeys: [],
      selectedRows: []
    }
  },
  created () {
    getRoleList({ t: new Date() })
  },
  computed: {
    rowSelection () {
      return {
        selectedRowKeys: this.selectedRowKeys,
        onChange: this.onSelectChange
      }
    }
  },
  methods: {
    add () {
      this.$dialog(TaskForm,
        // component props
        {
          record: {},
          on: {
            ok () {
              console.log('ok 回调')
            },
            cancel () {
              console.log('cancel 回调')
            },
            close () {
              console.log('modal close 回调')
            }
          }
        },
        // modal props
        {
          title: '新增',
          width: 700,
          centered: true,
          maskClosable: false
        })
    },
    edit (record) {
      console.log('record', record)
      this.$dialog(TaskForm,
        // component props
        {
          record,
          on: {
            ok () {
              console.log('ok 回调')
            },
            cancel () {
              console.log('cancel 回调')
            },
            close () {
              console.log('modal close 回调')
            }
          }
        },
        // modal props
        {
          title: '操作',
          width: 700,
          centered: true,
          maskClosable: false
        })
    },
    handleAdd () {
      this.mdl = null
      this.visible = true
    },
    handleEdit (record) {
      this.visible = true
      this.mdl = { ...record }
    },
    handleOk () {
      const form = this.$refs.createModal.form
      this.confirmLoading = true
      form.validateFields((errors, values) => {
        if (!errors) {
          console.log('values', values)
          if (values.id > 0) {
            // 修改 e.g.
            new Promise((resolve, reject) => {
              setTimeout(() => {
                resolve()
              }, 1000)
            }).then(res => {
              this.visible = false
              this.confirmLoading = false
              // 重置表单数据
              form.resetFields()
              // 刷新表格
              this.$refs.table.refresh()

              this.$message.info('修改成功')
            })
          } else {
            // 新增
            new Promise((resolve, reject) => {
              setTimeout(() => {
                resolve()
              }, 1000)
            }).then(res => {
              this.visible = false
              this.confirmLoading = false
              // 重置表单数据
              form.resetFields()
              // 刷新表格
              this.$refs.table.refresh()

              this.$message.info('新增成功')
            })
          }
        } else {
          this.confirmLoading = false
        }
      })
    },
    handleCancel () {
      this.visible = false

      const form = this.$refs.createModal.form
      form.resetFields() // 清理表单数据（可不做）
    },
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
    resetSearchForm () {
      this.queryParam = {
        date: moment(new Date())
      }
    }
  }
}
</script>

<style lang="less" scoped>
.table-page-search-wrapper {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  margin-bottom: 2%;
  .btnTitle {
    margin-left: 5%;
  }
}

.taskDetail {
  width: 60%;
  display: flex;
  align-items: center;
  .userName {
    margin-right: 5%;
    width: 10%;
  }
  .wordInfo {
    // 注意文本换行的后续处理
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
  }
}

.list-content-item {
    color: rgba(0, 0, 0, .45);
    display: inline-block;
    vertical-align: middle;
    font-size: 14px;
    margin-left: 10px;
    margin-right: 30px;
    span {
        line-height: 20px;
    }
    p {
        margin-top: 4px;
        margin-bottom: 0;
        line-height: 22px;
    }
}
</style>
